//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>
package org.jpgolay.wi.preferences;

import java.io.*;
import java.util.Properties;

public class PreferencesCRUD {

    public PreferencesCRUD() {
        numberOfDecimal = "";
        roundType = "";
        minimumProfitMargin = "";
        lookAndFeel = "";
        init();
    }

    private void init() {
        Properties p = new Properties();
        try {
            FileInputStream fis = new FileInputStream("lib/preferences.properties");
            p.load(fis);
            numberOfDecimal = p.getProperty("number_of_decimal");
            roundType = p.getProperty("round_type");
            minimumProfitMargin = p.getProperty("mini_profit_margin");
            lookAndFeel = p.getProperty("look_and_feel");
            printCustomerQuoteLaw = p.getProperty("print_customer_quote");
            printCustomerOrderLaw = p.getProperty("print_customer_order");
            printCustomerDeliveryLaw = p.getProperty("print_customer_delivery");
            printCustomerBillLaw = p.getProperty("print_customer_bill");
            printCustomerAssetLaw = p.getProperty("print_customer_asset");
            printSupplierOrderLaw = p.getProperty("print_supplier_order");
            printSupplierBillLaw = p.getProperty("print_supplier_bill");
            printSupplierAssetLaw = p.getProperty("print_supplier_asset");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }

    private void updateProperty() {
        Properties p = new Properties();
        p.setProperty("number_of_decimal", numberOfDecimal);
        p.setProperty("round_type", roundType);
        p.setProperty("mini_profit_margin", minimumProfitMargin);
        p.setProperty("look_and_feel", lookAndFeel);
        p.setProperty("print_customer_quote", printCustomerQuoteLaw);
        p.setProperty("print_customer_order", printCustomerOrderLaw);
        p.setProperty("print_customer_delivery", printCustomerDeliveryLaw);
        p.setProperty("print_customer_bill", printCustomerBillLaw);
        p.setProperty("print_customer_asset", printCustomerAssetLaw);
        p.setProperty("print_supplier_order", printSupplierOrderLaw);
        p.setProperty("print_supplier_bill", printSupplierBillLaw);
        p.setProperty("print_supplier_asset", printSupplierAssetLaw);
        try {
            p.store(new FileOutputStream("lib/preferences.properties"), "ME properties file user preferences");
        } catch (IOException ioe) {
            System.out.println("error Saving properties file: " + ioe);
        }
    }

    public void update() {
        updateProperty();
    }

    public String getNumberOfDecimal() {
        return numberOfDecimal;
    }

    public String getMinimumProfitMargin() {
        return minimumProfitMargin;
    }

    public String getLookAndFeel() {
        return lookAndFeel;
    }

    public void setNumberOfDecimal(String numberOfDecimal) {
        this.numberOfDecimal = numberOfDecimal;
    }

    public void setMinimumProfitMargin(String minimumProfitMargin) {
        this.minimumProfitMargin = minimumProfitMargin;
    }

    public void setLookAndFeel(String lookAndFeel) {
        this.lookAndFeel = lookAndFeel;
    }

    public String getRoundType() {
        return roundType;
    }

    public void setRoundType(String roundType) {
        this.roundType = roundType;
    }

    public String getPrintCustomerAssetLaw() {
        return printCustomerAssetLaw;
    }

    public void setPrintCustomerAssetLaw(String printCustomerAssetLaw) {
        this.printCustomerAssetLaw = printCustomerAssetLaw;
    }

    public String getPrintCustomerBillLaw() {
        return printCustomerBillLaw;
    }

    public void setPrintCustomerBillLaw(String printCustomerBillLaw) {
        this.printCustomerBillLaw = printCustomerBillLaw;
    }

    public String getPrintCustomerDeliveryLaw() {
        return printCustomerDeliveryLaw;
    }

    public void setPrintCustomerDeliveryLaw(String printCustomerDeliveryLaw) {
        this.printCustomerDeliveryLaw = printCustomerDeliveryLaw;
    }

    public String getPrintCustomerOrderLaw() {
        return printCustomerOrderLaw;
    }

    public void setPrintCustomerOrderLaw(String printCustomerOrderLaw) {
        this.printCustomerOrderLaw = printCustomerOrderLaw;
    }

    public String getPrintCustomerQuoteLaw() {
        return printCustomerQuoteLaw;
    }

    public void setPrintCustomerQuoteLaw(String printCustomerQuoteLaw) {
        this.printCustomerQuoteLaw = printCustomerQuoteLaw;
    }

    public String getPrintSupplierAssetLaw() {
        return printSupplierAssetLaw;
    }

    public void setPrintSupplierAssetLaw(String printSupplierAssetLaw) {
        this.printSupplierAssetLaw = printSupplierAssetLaw;
    }

    public String getPrintSupplierBillLaw() {
        return printSupplierBillLaw;
    }

    public void setPrintSupplierBillLaw(String printSupplierBillLaw) {
        this.printSupplierBillLaw = printSupplierBillLaw;
    }

    public String getPrintSupplierOrderLaw() {
        return printSupplierOrderLaw;
    }

    public void setPrintSupplierOrderLaw(String printSupplierOrderLaw) {
        this.printSupplierOrderLaw = printSupplierOrderLaw;
    }
    private String numberOfDecimal;
    private String roundType;
    private String minimumProfitMargin;
    private String lookAndFeel;
    private String printCustomerQuoteLaw;
    private String printCustomerOrderLaw;
    private String printCustomerDeliveryLaw;
    private String printCustomerBillLaw;
    private String printCustomerAssetLaw;
    private String printSupplierOrderLaw;
    private String printSupplierBillLaw;
    private String printSupplierAssetLaw;
}
